<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="专业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入专业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教学语言字典" prop="languageId">
        <el-select v-model="queryParams.languageId" placeholder="请选择教学语言字典" clearable :filterable="false">
          <el-option
            v-for="dict in teachLanguageOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学费" prop="tuition">
        <el-input
          v-model="queryParams.tuition"
          placeholder="请输入学费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间字典" prop="openingDateId">
        <el-select v-model="queryParams.openingDateId" placeholder="请选择开始时间字典" clearable :filterable="false">
          <el-option
            v-for="dict in eduPlanOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="院校ID" prop="schoolId">
        <el-input
          v-model="queryParams.schoolId"
          placeholder="请输入院校ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学位" prop="degree">
        <el-select v-model="queryParams.degree" placeholder="请选择学位" clearable :filterable="false">
          <el-option
            v-for="dict in degreeTypeOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="专业简介" prop="intro">
        <el-input
          v-model="queryParams.intro"
          placeholder="请输入专业简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序字段" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入排序字段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['degree:professions:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['degree:professions:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['degree:professions:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['degree:professions:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="professionsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="专业名称" align="center" prop="name" width="130" show-overflow-tooltip />
      <el-table-column label="教学语言" align="center" prop="languageId" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="teachLanguageOptions" :value="scope.row.languageId"/>
        </template>
      </el-table-column>
      <el-table-column label="学费" align="center" prop="tuition" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.tuition">{{ scope.row.tuition }}元</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="开学时间" align="center" prop="openingDateId" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="eduPlanOptions" :value="scope.row.openingDateId"/>
        </template>
      </el-table-column>
      <el-table-column label="院校ID" align="center" prop="schoolId" width="130" show-overflow-tooltip />
      <el-table-column label="学位" align="center" prop="degree" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="degreeTypeOptions" :value="scope.row.degree"/>
        </template>
      </el-table-column>
      <el-table-column label="二级标题" align="center" prop="subTitle" width="130" show-overflow-tooltip />
      <el-table-column label="学制" align="center" prop="years" width="130" show-overflow-tooltip />
      <el-table-column label="学历" align="center" prop="years" width="130" show-overflow-tooltip />
       <el-table-column label="学历" align="center" prop="years" width="130" show-overflow-tooltip />
      <el-table-column label="年龄" align="center" prop="intro" width="130" show-overflow-tooltip />
      <el-table-column label="语言" align="center" prop="intro" width="130" show-overflow-tooltip />
      <el-table-column label="成绩" align="center" prop="intro" width="130" show-overflow-tooltip />
      <el-table-column label="排序字段" align="center" prop="orderNum" width="130" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['degree:professions:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['degree:professions:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改院校展示对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body custom-class="profession-dialog">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="专业名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入专业名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="教学语言" prop="languageId">
              <el-select 
                v-model="form.languageId" 
                placeholder="请选择教学语言" 
                style="width: 100%" 
                clearable
                :filterable="false">
                <el-option
                  v-for="dict in teachLanguageOptions"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="学费" prop="tuition">
              <el-input 
                v-model="form.tuition" 
                placeholder="请输入学费"
                type="number"
                :min="0"
                :precision="2"
                @input="handleTuitionInput">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开学时间">
            <el-checkbox-group v-model="openingDateArray" style="width: 100%">
              <el-checkbox label="1">春季开学</el-checkbox>
              <el-checkbox label="2">秋季开学</el-checkbox>
            </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="学位" prop="degree">
              <el-select 
                v-model="form.degree" 
                placeholder="请选择学位" 
                style="width: 100%" 
                clearable
                :filterable="false">
                <el-option
                  v-for="dict in degreeTypeOptions"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="院校ID" prop="schoolId">
              <el-input v-model="form.schoolId" placeholder="请输入院校ID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序字段" prop="orderNum">
              <el-input v-model="form.orderNum" placeholder="请输入排序字段" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="专业简介" prop="intro">
              <el-input v-model="form.intro" placeholder="请输入专业简介" maxlength="500" show-word-limit />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProfessions, getProfessions, delProfessions, addProfessions, updateProfessions } from "@/api/degree/professions"

export default {
  name: "Professions",
  dicts: ['teachlanguage', 'edu_plan', 'degree_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 院校展示表格数据
      professionsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openingDateArray:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        languageId: null,
        tuition: null,
        openingDateId: null,
        schoolId: null,
        degree: null,
        intro: null,
        orderNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: '请输入专业名称', trigger: 'blur' }
        ],
        languageId: [
          { required: true, message: '请选择教学语言', trigger: 'change' }
        ],
        tuition: [
          { required: true, message: '请输入学费', trigger: 'blur' },
          { pattern: /^[0-9]+(\.[0-9]{1,2})?$/, message: '学费必须是数字，最多保留两位小数', trigger: 'blur' }
        ],
        openingDateId: [
          { required: true, message: '请选择开学时间', trigger: 'change' }
        ],
        degree: [
          { required: true, message: '请选择学位', trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    // 计算属性确保字典数据能正确访问
    teachLanguageOptions() {
      const dicts = this.dict.type.teachlanguage
      if (!dicts) return []
      // 将DictData对象转换为普通数组
      return Array.isArray(dicts) ? dicts : Object.values(dicts)
    },
    eduPlanOptions() {
      const dicts = this.dict.type.edu_plan
      if (!dicts) return []
      return Array.isArray(dicts) ? dicts : Object.values(dicts)
    },
    degreeTypeOptions() {
      const dicts = this.dict.type.degree_type
      if (!dicts) return []
      return Array.isArray(dicts) ? dicts : Object.values(dicts)
    }
  },
  created() {
    console.log('专业页面组件创建，检查字典数据状态...')
    console.log('teachlanguage字典:', this.dict.type.teachlanguage)
    console.log('edu_plan字典:', this.dict.type.edu_plan)
    console.log('degree_type字典:', this.dict.type.degree_type)
    
    // 检查字典数据结构
    this.$nextTick(() => {
      if (this.teachLanguageOptions && this.teachLanguageOptions.length > 0) {
        console.log('教学语言选项示例:', this.teachLanguageOptions[0])
        console.log('教学语言选项值类型:', typeof this.teachLanguageOptions[0].value)
      }
      if (this.eduPlanOptions && this.eduPlanOptions.length > 0) {
        console.log('开学时间选项示例:', this.eduPlanOptions[0])
        console.log('开学时间选项值类型:', typeof this.eduPlanOptions[0].value)
      }
      if (this.degreeTypeOptions && this.degreeTypeOptions.length > 0) {
        console.log('学位选项示例:', this.degreeTypeOptions[0])
        console.log('学位选项值类型:', typeof this.degreeTypeOptions[0].value)
      }
    })
    
    this.getList()
  },
  methods: {
    /** 处理学费输入，确保只能输入数字 */
    handleTuitionInput(value) {
      // 移除非数字字符（除了小数点）
      const numericValue = value.replace(/[^0-9.]/g, '')
      
      // 确保只有一个小数点
      const parts = numericValue.split('.')
      if (parts.length > 2) {
        this.form.tuition = parts[0] + '.' + parts.slice(1).join('')
      } else {
        this.form.tuition = numericValue
      }
      
      // 限制小数点后最多两位
      if (parts.length === 2 && parts[1].length > 2) {
        this.form.tuition = parts[0] + '.' + parts[1].substring(0, 2)
      }
    },

    /** 查询院校展示列表 */
    getList() {
      this.loading = true
      listProfessions(this.queryParams).then(response => {
        this.professionsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        languageId: null, // 使用null避免校验警告
        tuition: null,
        openingDateId: null, // 使用null避免校验警告
        schoolId: null,
        degree: null, // 使用null避免校验警告
        intro: null,
        orderNum: null
      }
      // 先重置表单，再清除校验状态
      this.resetForm("form")
      // 清除表单校验状态，避免校验警告
      this.$nextTick(() => {
        if (this.$refs.form) {
          this.$refs.form.clearValidate()
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      // 检查字典数据是否就绪
      if (!this.isDictDataReady()) {
        this.$modal.msgWarning('字典数据尚未加载完成，请稍后再试')
        return
      }
      this.open = true
      this.title = "添加院校展示"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      
      // 检查字典数据是否就绪
      if (!this.isDictDataReady()) {
        this.$modal.msgWarning('字典数据尚未加载完成，请稍后再试')
        return
      }
      
      const id = row.id || this.ids
      getProfessions(id).then(response => {
        // 编辑前处理数据
        this.prepareFormData(response.data)
        
        this.open = true
        this.title = "修改院校展示"
      })
    },

    /** 编辑专业数据前的处理 */
    prepareFormData(data) {
      // 直接设置表单数据，不使用nextTick
      this.form = {
        ...data,
        // 确保字典字段为数字类型，但保留原值作为备选
        languageId: this.ensureNumericValue(data.languageId) || data.languageId,
        openingDateId: this.ensureNumericValue(data.openingDateId) || data.openingDateId,
        degree: this.ensureNumericValue(data.degree) || data.degree
      }
      
      console.log('表单数据准备完成:', this.form)
      console.log('字典字段类型检查:', {
        languageId: { value: this.form.languageId, type: typeof this.form.languageId },
        openingDateId: { value: this.form.openingDateId, type: typeof this.form.openingDateId },
        degree: { value: this.form.degree, type: typeof this.form.degree }
      })
      
      // 延迟验证，确保表单已渲染
      this.$nextTick(() => {
        this.validateDictValues()
      })
    },

    /** 验证字典值是否有效 */
    validateDictValues() {
      const validations = [
        {
          value: this.form.languageId,
          dictKey: 'teachlanguage',
          fieldName: '教学语言'
        },
        {
          value: this.form.openingDateId,
          dictKey: 'edu_plan',
          fieldName: '开学时间'
        },
        {
          value: this.form.degree,
          dictKey: 'degree_type',
          fieldName: '学位'
        }
      ]
      
      validations.forEach(({ value, dictKey, fieldName }) => {
        if (value !== '' && value !== null && value !== undefined) {
          const dictOptions = this.dict.type[dictKey]
          const isValid = dictOptions && dictOptions.some(option => 
            parseInt(option.value) === parseInt(value)
          )
          
          if (!isValid) {
            console.warn(`${fieldName}字典值无效:`, {
              当前值: value,
              当前类型: typeof value,
              字典选项: dictOptions ? dictOptions.map(opt => ({ value: opt.value, label: opt.label })) : '字典未加载'
            })
          } else {
            console.log(`${fieldName}字典值有效:`, value)
          }
        }
      })
    },

    /** 确保值为数字类型，用于字典选择器 */
    ensureNumericValue(value) {
      console.log(`类型转换: 原始值=${value}, 类型=${typeof value}`)
      
      // 如果值为空、null、undefined，返回空字符串（便于el-select识别）
      if (value === null || value === undefined || value === '') {
        console.log('值为空，返回空字符串')
        return ''
      }
      
      // 尝试转换为数字
      const numValue = parseInt(value)
      
      // 如果转换失败（NaN），返回空字符串而不是原值
      if (isNaN(numValue)) {
        console.warn('无法将值转换为数字:', value, '返回空字符串')
        return ''
      }
      
      console.log(`转换成功: ${value} -> ${numValue}`)
      return numValue
    },
    /** 提交按钮 */
    submitForm() {
      // 先检查字典数据是否就绪
      if (!this.isDictDataReady()) {
        this.$modal.msgWarning('字典数据尚未加载完成，请稍后再试')
        return
      }
      
      console.log('提交前表单数据:', this.form)
      
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 确保数据完整性
          const formData = { ...this.form }
          
          // 确保 id 字段是数字类型或 null
          if (formData.id !== null && formData.id !== undefined && formData.id !== '') {
            const idNum = Number(formData.id)
            formData.id = isNaN(idNum) ? null : idNum
          }
          
          // 验证必填字段
          if (!formData.name || formData.name.trim() === '') {
            this.$modal.msgError('请输入专业名称')
            return
          }
          
          if (formData.languageId === null || formData.languageId === undefined || formData.languageId === '') {
            this.$modal.msgError('请选择教学语言')
            return
          }
          
          if (!formData.tuition && formData.tuition !== 0) {
            this.$modal.msgError('请输入学费')
            return
          }
          
          if (formData.openingDateId === null || formData.openingDateId === undefined || formData.openingDateId === '') {
            this.$modal.msgError('请选择开学时间')
            return
          }
          
          if (formData.degree === null || formData.degree === undefined || formData.degree === '') {
            this.$modal.msgError('请选择学位')
            return
          }
          
          // 确保数字字段类型正确
          formData.tuition = parseFloat(formData.tuition) || 0
          
          // 对于字典字段，确保它们是有效的数字（包括0）
          if (formData.languageId !== '' && formData.languageId !== null && formData.languageId !== undefined) {
            const langIdNum = Number(formData.languageId)
            if (isNaN(langIdNum) || langIdNum < 0) {
              this.$modal.msgError('教学语言选择无效，请重新选择')
              return
            }
            formData.languageId = langIdNum
          } else {
            this.$modal.msgError('请选择教学语言')
            return
          }
          
          if (formData.openingDateId !== '' && formData.openingDateId !== null && formData.openingDateId !== undefined) {
            const openDateIdNum = Number(formData.openingDateId)
            if (isNaN(openDateIdNum) || openDateIdNum < 0) {
              this.$modal.msgError('开学时间选择无效，请重新选择')
              return
            }
            formData.openingDateId = openDateIdNum
          } else {
            this.$modal.msgError('请选择开学时间')
            return
          }
          
          if (formData.degree !== '' && formData.degree !== null && formData.degree !== undefined) {
            const degreeNum = Number(formData.degree)
            if (isNaN(degreeNum) || degreeNum < 0) {
              this.$modal.msgError('学位选择无效，请重新选择')
              return
            }
            formData.degree = degreeNum
          } else {
            this.$modal.msgError('请选择学位')
            return
          }
          
          // 特别处理 schoolId，确保它是有效的数字
          if (formData.schoolId && formData.schoolId !== '') {
            const schoolIdNum = Number(formData.schoolId)
            if (isNaN(schoolIdNum) || schoolIdNum <= 0) {
              this.$modal.msgError('院校ID无效，请输入有效的数字')
              return
            }
            formData.schoolId = schoolIdNum
          } else {
            this.$modal.msgError('请输入院校ID')
            return
          }
          
          // 处理 orderNum
          if (formData.orderNum && formData.orderNum !== '') {
            const orderNumVal = parseInt(formData.orderNum)
            formData.orderNum = isNaN(orderNumVal) ? null : orderNumVal
          } else {
            formData.orderNum = null
          }
          
          console.log('提交数据（最终）:', formData)
          console.log('提交数据类型检查:', {
            id: { value: formData.id, type: typeof formData.id },
            schoolId: { value: formData.schoolId, type: typeof formData.schoolId },
            languageId: { value: formData.languageId, type: typeof formData.languageId },
            openingDateId: { value: formData.openingDateId, type: typeof formData.openingDateId },
            degree: { value: formData.degree, type: typeof formData.degree },
            tuition: { value: formData.tuition, type: typeof formData.tuition }
          })
          
          // 清理数据，确保所有字段都是基本数据类型
          const cleanFormData = {
            id: formData.id,
            name: String(formData.name || ''),
            languageId: Number(formData.languageId),
            tuition: Number(formData.tuition),
            openingDateId: Number(formData.openingDateId),
            schoolId: Number(formData.schoolId),
            degree: Number(formData.degree),
            intro: String(formData.intro || ''),
            requirements: String(formData.requirements || ''),
            eduPlanAdvantage: String(formData.eduPlanAdvantage || ''),
            orderNum: formData.orderNum
          }
          
          console.log('清理后的提交数据:', cleanFormData)
          console.log('清理后的数据类型检查:', {
            id: { value: cleanFormData.id, type: typeof cleanFormData.id },
            schoolId: { value: cleanFormData.schoolId, type: typeof cleanFormData.schoolId },
            languageId: { value: cleanFormData.languageId, type: typeof cleanFormData.languageId },
            openingDateId: { value: cleanFormData.openingDateId, type: typeof cleanFormData.openingDateId },
            degree: { value: cleanFormData.degree, type: typeof cleanFormData.degree },
            tuition: { value: cleanFormData.tuition, type: typeof cleanFormData.tuition }
          })
          
          // 最终数据验证（对清理后的数据进行验证）
          if (!Number.isInteger(cleanFormData.schoolId) || cleanFormData.schoolId <= 0) {
            this.$modal.msgError('院校ID必须是有效的正整数')
            return
          }
          
          if (!Number.isInteger(cleanFormData.languageId) || cleanFormData.languageId < 0) {
            this.$modal.msgError('教学语言ID必须是有效的非负整数')
            return
          }
          
          if (!Number.isInteger(cleanFormData.openingDateId) || cleanFormData.openingDateId < 0) {
            this.$modal.msgError('开学时间ID必须是有效的非负整数')
            return
          }
          
          if (!Number.isInteger(cleanFormData.degree) || cleanFormData.degree < 0) {
            this.$modal.msgError('学位ID必须是有效的非负整数')
            return
          }
          
          if (formData.id != null) {
            updateProfessions(cleanFormData).then(response => {
              console.log('更新响应:', response)
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            }).catch(error => {
              console.error('更新失败:', error)
              this.$modal.msgError("修改失败：" + (error.msg || error.message || '未知错误'))
            })
          } else {
            addProfessions(cleanFormData).then(response => {
              console.log('新增响应:', response)
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            }).catch(error => {
              console.error('新增失败:', error)
              this.$modal.msgError("新增失败：" + (error.msg || error.message || '未知错误'))
            })
          }
        } else {
          console.log('表单验证失败')
          this.$modal.msgError('请检查表单数据')
        }
      })
    },

    /** 检查字典数据是否就绪 */
    isDictDataReady() {
      const requiredDicts = ['teachlanguage', 'edu_plan', 'degree_type']
      
      for (const dictKey of requiredDicts) {
        const dictData = this.dict.type[dictKey]
        if (!dictData || !Array.isArray(dictData) || dictData.length === 0) {
          console.warn(`字典数据未就绪: ${dictKey}`, dictData)
          return false
        }
      }
      
      console.log('所有字典数据已就绪')
      return true
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除院校展示编号为"' + ids + '"的数据项？').then(function() {
        return delProfessions(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('degree/professions/export', {
        ...this.queryParams
      }, `professions_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>
/* 专业弹出框高度设置 */
::v-deep .profession-dialog {
  height: 70vh;
}

::v-deep .profession-dialog .el-dialog__body {
  height: calc(70vh - 120px);
  overflow-y: auto;
  padding: 20px;
}
</style>
